﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.Model;
namespace CMSWCSFSolution.CMS
{
    /// <summary>
    /// Summary description for CourseListcomparer
    /// </summary>
    public class CourseListcomparer
    {
        public enum CompareType
        {
            CourseId,
            CourseName,
            CourseStatus,
            TeacherName,
            LevelName,
            StudentNumber
        }
        public class CourseListComparer : IComparer<CourseList>
        {
            private CompareType _compareColumn;

            public CompareType CompareColumn
            {
                get { return _compareColumn; }
                set { _compareColumn = value; }
            }

            public CourseListComparer(CompareType t)
            {
                this._compareColumn = t;

            }

            /// <summary>
            /// compare by different property
            /// </summary>
            /// <param name="x">CourseList x</param>
            /// <param name="y">CourseList y</param>
            /// <returns>int </returns>
            public int Compare(CourseList x, CourseList y)
            {

                //CompileType sort = (CompileType)Enum.Parse(typeof(CompileType), "ID");
                switch (this.CompareColumn)
                {
                    case CompareType.CourseId:
                        return x.CourseId.CompareTo(y.CourseId);
                    case CompareType.CourseName:
                        return x.CourseName.CompareTo(y.CourseName);
                    case CompareType.CourseStatus:
                        return x.CourseStatus.CompareTo(y.CourseStatus);
                    case CompareType.TeacherName:
                        return x.TeacherName.CompareTo(y.TeacherName);
                    case CompareType.LevelName:
                        return x.LevelName.CompareTo(y.LevelName);
                    case CompareType.StudentNumber:
                        return x.StudentNumber.CompareTo(y.StudentNumber);
                    default: return x.CourseId.CompareTo(y.CourseId);

                }
            }
        }
    }
}